//
//  BaseTableViewController.swift
//  DSWeiBo
//
//  Created by H on 16/4/12.
//  Copyright © 2016年 Mr.Lin. All rights reserved.
//

import UIKit

class BaseTableViewController: UITableViewController,VisitorViewDelegate {

    //定义一个变量保存用户当前是否登录
    var userLogin = Useraccount.userLogin()
    var visitorView : VisitorView?
    
    
    override func loadView() {
        userLogin ? super.loadView() : setupVisitorView()
    }
   
    
    private func setupVisitorView() {
        
        //1.初始化未登录界面
        let customView = VisitorView()
        view = customView
        customView.delegate = self
        visitorView = customView
        
        //2. 设置导航栏未登录按钮
        navigationItem.leftBarButtonItem = UIBarButtonItem(title:"注册",style: UIBarButtonItemStyle.Plain,target: self,action: #selector(BaseTableViewController.registerBtnWillClick))
        navigationItem.rightBarButtonItem = UIBarButtonItem(title:"登录",style: UIBarButtonItemStyle.Plain,target: self,action: #selector(BaseTableViewController.loginBtnWillClick))
        
    }
    override func viewWillAppear(animated: Bool) {
        
    }
    
    
    //MARK:- VisitorViewDelegate
    
    
    func loginBtnWillClick() {
    
        let outhVC = OAuthViewController()
        let nav = UINavigationController(rootViewController:outhVC)
        presentViewController(nav, animated: true, completion: nil)
        
    }
    
    func registerBtnWillClick() {
        print("baseRe")
    }
  }
